# 需求: 实现扑克牌游戏

import time

# 扑克牌的基础数据
POKER_DICT = {
    'number': ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2'],
    'type': ["♠", "♥", "♣", "♦"]
}


class Poker:
    def __init__(self, poker_number: int = 1, person_number: int = 4, ):
        self.poker_number = poker_number
        self.poker_list = []
        # 定义集合存储玩家的牌
        self.person_number = person_number
        self.person_poker_list = []

    def build(self):
        # 定义一个poker数字
        poker_number = []
        for number in range(13):
            poker_number.append("%02d" % number)
        poker_type = ['00', '01', '02', '03']
        # 生成扑克牌  几副牌 >> 数字 >> 花色
        for pair in range(self.poker_number):
            for number in poker_number:
                for type in poker_type:
                    self.poker_list.append(number + type)
        print(str(self.poker_list))

    def print_all_poker(self, print_list: list):
        # 打印所有的牌
        for one_poker in print_list:
            print("%s%s" % (POKER_DICT['type'][int(one_poker[2:])], POKER_DICT['number'][int(one_poker[:2])]), end="\t")

    def deal_poker(self):
        '''发牌'''
        for person_index in range(self.person_number):
            temp_list = []
            # 遍历牌
            for index in range(len(self.poker_list)):
                if index % self.person_number == person_index:  # 根据玩家的序号 取余
                    temp_list.append(self.poker_list[index])
            self.person_poker_list.append(temp_list)
            print(temp_list)

    def print_person_poker(self):
        """打印玩家的牌"""
        for index, value in enumerate(self.person_poker_list):
            # 换行
            print()
            print("第%d家的牌: " % index, end="")
            self.print_all_poker(self.person_poker_list[index])

    def start(self):
        print("正在启动游戏......")
        time.sleep(1)
        print("游戏启动成功")
        while True:
            print()
            print("=" * 30 + "poker GAME START" + "=" * 30)
            input_type = input("开始游戏 【1-生成牌 2-打印所有牌 3-发牌 4-打印玩家牌 5-洗牌 6-整理牌 7-退出】:")
            if input_type == '1':
                print("正在生成扑克牌......")
                time.sleep(1)
                self.build()
                print("生成扑克牌完成")
            elif input_type == '2':
                self.print_all_poker(self.poker_list)
            elif input_type == '3':
                self.deal_poker()
            elif input_type == '4':
                self.print_person_poker()
            elif input_type == '5':
                pass
            elif input_type == '6':
                pass
            elif input_type == '7':
                pass
            else:
                print("指令错误!!!")


if __name__ == '__main__':
    obj = Poker(1)
    obj.start()
